package com.sk.weichat.view;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.text.Html;
import android.view.Display;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.sk.weichat.R;
import com.sk.weichat.bean.VersionInfo;
import com.sk.weichat.downloader.UpdateManger;
import com.sk.weichat.util.ToastUtil;

public class DownLodingDialog extends AlertDialog {

    private Activity context;
    private TextView tvProgress;
    private ProgressBar progressBar;
    public DownLodingDialog(Activity context) {
        super(context, R.style.alert_dialog);
        this.context = context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.custom_download_layout);
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
        Window dialogWindow = this.getWindow();
        WindowManager m = context.getWindowManager();
        Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用
        WindowManager.LayoutParams p = dialogWindow.getAttributes(); // 获取对话框当前的参数值
        p.width = (int) (d.getWidth() * 0.8); // 宽度设置为屏幕的0.8
        dialogWindow.setAttributes(p);
        initView();
    }

    private void initView(){
        tvProgress = findViewById(R.id.tv_progress);
        progressBar = findViewById(R.id.pb);


    }

    public void onDownloading(int progress){
        progressBar.setProgress(progress);
        tvProgress.setText(progress+"%");
    }


}
